package com.learning.javaweb_springboot_page_query.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learning.javaweb_springboot_page_query.entity.User;
import com.learning.javaweb_springboot_page_query.mapper.UserMapper;
import com.learning.javaweb_springboot_page_query.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserMapper userMapper;


    @Autowired
    UserService userService;

    //分页查询请求
    @GetMapping("/user/findAll1")
    public IPage findAll(){
       Page<User> gage=new Page<>(0,2);
       return userMapper.selectPage(gage,null);
    }


    //多表查询请求
    @GetMapping("/user/findAll2")
    public List<User> find(){
        return userMapper.selectAllUserAndOrders();
    }


    // 单表查询，查询全部学生
    @GetMapping("/users")
    public List<User> queryAllUser() {
        return userService.queryAllUser();
    }

    // 单表查询，根据ID查询用户
    @GetMapping("/users/{id}")
    public User queryUserById(@PathVariable Integer id) {
       return userService.queryUserById(id);

    }

}
